package com.dynamixsoftware.printershare.mdns;

import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class DnsRecordAddress
  extends DnsRecord
{
  InetAddress addr;
  
  DnsRecordAddress(String paramString, int paramInt1, int paramInt2, int paramInt3, InetAddress paramInetAddress)
  {
    super(paramString, paramInt1, paramInt2, paramInt3);
    this.addr = paramInetAddress;
  }
  
  DnsRecordAddress(String paramString, int paramInt1, int paramInt2, int paramInt3, byte[] paramArrayOfByte)
    throws UnknownHostException
  {
    super(paramString, paramInt1, paramInt2, paramInt3);
    this.addr = InetAddress.getByAddress(paramArrayOfByte);
  }
  
  public InetAddress getAddress()
  {
    return this.addr;
  }
  
  boolean same(DnsRecord paramDnsRecord)
  {
    return (sameName(paramDnsRecord)) && (sameValue(paramDnsRecord));
  }
  
  boolean sameName(DnsRecord paramDnsRecord)
  {
    return this.name.equalsIgnoreCase(((DnsRecordAddress)paramDnsRecord).name);
  }
  
  boolean sameValue(DnsRecord paramDnsRecord)
  {
    return this.addr.equals(((DnsRecordAddress)paramDnsRecord).getAddress());
  }
  
  void write(DnsPacketOut var1) throws IOException {
      if(this.addr != null) {
         byte[] var2 = this.addr.getAddress();
         if(1 == this.type) {
            if(!(this.addr instanceof Inet4Address)) {
               byte[] var5 = var2;
               var2 = new byte[4];
               System.arraycopy(var5, 12, var2, 0, 4);
            }
         } else if(this.addr instanceof Inet4Address) {
            byte[] var3 = var2;
            var2 = new byte[16];

            for(int var4 = 0; var4 < 16; ++var4) {
               if(var4 < 11) {
                  var2[var4] = var3[var4 - 12];
               } else {
                  var2[var4] = 0;
               }
            }
         }

         var1.writeBytes(var2);
      }

   }
}

